package asteroids.statement;

import asteroids.*;
import asteroids.model.programs.*;

import asteroids.expression.*;

public class TurnStatement extends ActionStatement {

	Expression e;
	
	public TurnStatement(Expression e) {
		if(e != null && ((e instanceof NumericExpression)||(e instanceof Variable)))
			this.e = e;
		else e = new asteroids.expression.DoubleLiteral(0);
	}
	
	@Override
	public void execute(Program program) {
		Expression exp=e;
		if(e instanceof Variable){
			if(((Variable)e).getRef(program) instanceof NumericExpression){
				exp = ((Variable)e).getRef(program);
			}else{
				exp = new asteroids.expression.DoubleLiteral(0.1);
			}
		}
		
			Ship ship = program.getOwner();
		ship.turn(((NumericExpression)exp).getValue(program));
		
		this.finished = true;
	}

}
